﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using gfLibrary;
using System.Drawing;
using IYAKASAPortal.Services;
using System.Data;
using System.Xml.Linq;
using System.IO;
using System.Xml;
using System.Web.UI.HtmlControls;
using DBUtility;


namespace IYAKASAPortal.Login
{
    public partial class LoginAJGC : System.Web.UI.Page
    {
        private UserInfo userInfo { get; set; }
        private static List<ListItem> lstItemsGC { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
            {
                string userName = Session["UserName"].ToString();
                userInfo = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName);
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }

            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            lstItemsGC = new List<ListItem>();
            CONST_DEFINE_BLL bll = new CONST_DEFINE_BLL();
            var def = bll.GetModelList("CON_CHNAME='JYLB' and CON_VTYPE='2' order by CON_ORDER asc");

            ListItem item;
            foreach (var v in def)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpTestTypeGC.Items.Add(item);
            }

            var hpzl = bll.GetModelList("CON_CHNAME='HPZL' and CON_CODE='15' order by CON_ORDER asc");
            foreach (var v in hpzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpHPZLGC.Items.Add(item);
            }

            var syxz = bll.GetModelList("CON_CHNAME='SYXZ' order by CON_ORDER asc");
            foreach (var v in syxz)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpSYXZGC.Items.Add(item);
            }

            var gcclzl = bll.GetModelList("CON_CHNAME='CLZL' and SUBSTRING(CON_CODE,1,1)='B' order by CON_ORDER asc");
            foreach (var v in gcclzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpCLZLGC.Items.Add(item);
            }

            var lwcxwzjl = bll.GetModelList("CON_CHNAME='LWCXWZJL' order by CON_ORDER asc");
            foreach (var v in lwcxwzjl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpLWCXGC.Items.Add(item);
            }

            var jyxm = bll.GetModelList("CON_CHNAME='JYXM' and CON_JCTYPE like '%02,%' order by CON_ORDER asc");
            foreach (var v in jyxm)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                lstItemsGC.Add(item);
            }

            for (int i = 2; i < 7; i++)
            {
                item = new ListItem();
                item.Text = i.ToString();
                item.Value = i.ToString();
                drpZZSGC.Items.Add(item);
            }

            //绑定号码开头
            CONST_DEFINE_WEB_CATEGORY_BLL category_bll = new CONST_DEFINE_WEB_CATEGORY_BLL();
            var hphmStart = category_bll.GetModel(8);
            txtHPHMStartGC.Text = hphmStart.CategoryName;

            BindZCZWZ(Convert.ToInt32(drpZZSGC.SelectedValue), chkZCZWZGC);

            ReBindJCXM();
        }

        protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAll.Checked)
            {
                for (int i = 0; i < chkJYXMGC.Items.Count; i++)
                {
                    chkJYXMGC.Items[i].Selected = true;
                }
            }
            else
            {
                for (int i = 0; i < chkJYXMGC.Items.Count; i++)
                {
                    chkJYXMGC.Items[i].Selected = false;
                }
            }
        }

        private void ResetAllGC()
        {
            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpTestTypeGC.ID,""));
            lstControls.Add(drpTestTypeGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAJLSHGC.ID, ""));
            lstControls.Add(txtAJLSHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMGC.ID, ""));
            lstControls.Add(txtHPHMGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZLGC.ID, ""));
            lstControls.Add(drpHPZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID, "2,"));
            lstControls.Add(chkZCZWZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtVINGC.ID, ""));
            lstControls.Add(txtVINGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID, ""));
            lstControls.Add(drpCLZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYRGC.ID, ""));
            lstControls.Add(txtSYRGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddressGC.ID, ""));
            lstControls.Add(txtAddressGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtTelGC.ID, ""));
            lstControls.Add(txtTelGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZGC.ID, ""));
            lstControls.Add(drpSYXZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtPPGC.ID, ""));
            lstControls.Add(txtPPGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtXHGC.ID, ""));
            lstControls.Add(txtXHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQGC.ID, ""));
            lstControls.Add(txtCCRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCDJRQGC.ID, ""));
            lstControls.Add(txtCCDJRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID, ""));
            lstControls.Add(txtZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID, ""));
            lstControls.Add(txtZBZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID, ""));
            lstControls.Add(txtHDZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID, ""));
            lstControls.Add(txtCSCGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID, ""));
            lstControls.Add(txtCSKGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID, ""));
            lstControls.Add(txtCSGGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpLWCXGC.ID, ""));
            lstControls.Add(drpLWCXGC);

            LoginHelper.ResetAllControls(lstCtl, lstControls);

            drpZZSGC_SelectedIndexChanged(null, null);
            lstItemsGC.All(x => x.Selected = false);

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                chkJYXMGC.Items[i].Selected = false;
            }

            chkTogether.Checked = false;
            txtGLHPHM.Text = "";
            chkTogether_CheckedChanged(null, null);

            btnSaveGC.Enabled = true;
            btnSaveGC.CssClass = "btnSaveEnabled";
        }

        private static LOGIN_VEHICLE_INFO GetData(string xmlString)
        {
            Model.LOGIN_VEHICLE_INFO info = new LOGIN_VEHICLE_INFO();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlString);
            XmlNodeList xxList = doc.GetElementsByTagName("body");
            foreach (XmlNode xxNode in xxList)
            {
                XmlNodeList childList = xxNode.ChildNodes;
                foreach (XmlNode node in childList)
                {
                    string temp = node.Name;
                    switch (temp)
                    {
                        case "clxh":
                            info.XH = node.InnerText;
                            break;
                        case "zzl":
                            info.ZZL = node.InnerText;
                            break;
                    }
                }
            }
            return info;
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            ResetAllGC();
        }

        protected void btnSendGC_Click(object sender, EventArgs e)
        {
            bool bIsFirstTest_GC = rbtnTestGC.SelectedValue == "0" ? true : false;//是否为初检

            //bool bHasCharge = LoginHelper.HasCharge(hidGCID.Value, "A", bIsFirstTest_GC);
            //if (!bHasCharge)
            //{
            //    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前车辆没有收费，请收费后在发送！");
            //    return;
            //}

            var dicCheckItems = LoginHelper.CheckAllInputItems("", hidGCID.Value, "A");
            if (dicCheckItems["AG"].Count > 0)
            {
                foreach (var v in dicCheckItems["AG"])
                {
                    TextBox txt = (TextBox)this.FindControl(v);
                    txt.BackColor = Color.Yellow;
                }
                return;
            }

            LOGIN_VEHICLE_INFO_BLL info_bll = new LOGIN_VEHICLE_INFO_BLL();
            var infoGC = info_bll.GetModel(Convert.ToInt32(hidGCID.Value));
            if (string.IsNullOrEmpty(infoGC.JYXM))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择检验挂车项目保存后，在进行发送！");
                return;
            }

            bool bIsUpdate_GC;
            VEHICLE_DISPATCH model_GC = LoginHelper.GetDispathchByLoginID(hidGCID.Value, "A", bIsFirstTest_GC, out bIsUpdate_GC);

            VEHICLE_DISPATCH_BLL disBll = new VEHICLE_DISPATCH_BLL();

            if (!bIsUpdate_GC)
            {
                if (disBll.Insert(model_GC))
                {
                    //LoginHelper.UpdateGCInfo(info, model.JCLSH, hidGLCJCLSH.Value, chkTogether.Checked, "A", bIsFirstTest);
                    gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送成功！");
                    btnSendGC.CssClass = "btnSendDisabled";
                    btnSendGC.Enabled = false;
                    ResetAllGC();
                    LoginedList1.BindList("", "");
                    return;
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送失败！");
                    btnSendGC.CssClass = "btnSendEnabled";
                    btnSendGC.Enabled = true;
                    return;
                }
            }
            else
            {
                if (disBll.Update(model_GC, model_GC.JCLSH))
                {
                    gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送成功！");
                    btnSendGC.CssClass = "btnSendDisabled";
                    btnSendGC.Enabled = false;
                    ResetAllGC();
                    LoginedList1.BindList("", "");
                    return;
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送失败！");
                    btnSendGC.CssClass = "btnSendEnabled";
                    btnSendGC.Enabled = true;
                    return;
                }
            }
        }

        private void BindZCZWZ(int iZZS, CheckBoxList chk)
        {
            ListItem item;
            chk.Items.Clear();
            for (int i = 1; i < iZZS + 1; i++)
            {
                item = new ListItem();
                item.Text = i.ToString();
                item.Value = i.ToString();
                chk.Items.Add(item);
            }
            chk.Items[1].Selected = true;
        }

        private void ReBindJCXM()
        {
            int iZZS = Convert.ToInt32(drpZZSGC.SelectedValue);

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                foreach (var vItem in lstItemsGC)
                {
                    if (chkJYXMGC.Items[i].Selected && chkJYXMGC.Items[i].Value == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }

            chkJYXMGC.Items.Clear();

            for (int i = 0; i < lstItemsGC.Count; i++)
            {
                if (lstItemsGC[i].Value.Substring(0, 1) == "B")
                {
                    if (Convert.ToInt32(lstItemsGC[i].Value.Substring(1, 1)) <= iZZS)
                    {
                        chkJYXMGC.Items.Add(lstItemsGC[i]);
                    }
                }
                else if (lstItemsGC[i].Value.Substring(0, 1) == "Z")
                {
                    if (Convert.ToInt32(lstItemsGC[i].Value.Substring(1, 1)) <= iZZS)
                    {
                        chkJYXMGC.Items.Add(lstItemsGC[i]);
                    }
                }

                else if (lstItemsGC[i].Value.Substring(0, 1) == "H")
                {

                }
                else
                {
                    chkJYXMGC.Items.Add(lstItemsGC[i]);
                }
            }
        }

        protected void drpZZSGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReBindJCXM();
            int iZZS = Convert.ToInt32(drpZZSGC.SelectedValue);
            BindZCZWZ(iZZS, chkZCZWZGC);
        }

        protected void chkJYXMGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            List<string> lstSelected = new List<string>();

            bool bFirstTestGC = rbtnTestGC.SelectedValue == "0" ? true : false;

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                if (bFirstTestGC)
                {
                    if (chkJYXMGC.Items[i].Selected && chkJYXMGC.Items[i].Value.Substring(0, 1) != "Z")
                    {
                        lstSelected.Add(chkJYXMGC.Items[i].Value);
                    }
                }
                else
                {
                    if (chkJYXMGC.Items[i].Selected)
                    {
                        {
                            lstSelected.Add(chkJYXMGC.Items[i].Value);
                        }
                    }
                }
            }

            if (bFirstTestGC)
            {
                var cur = lstSelected.Where(x => x.Substring(0, 1) == "B" && Convert.ToInt32(x.Substring(1, 1)) > 0 && Convert.ToInt32(x.Substring(1, 1)) < 9).ToList();

                foreach (var v in cur)
                {
                    lstSelected.Add("Z" + v.Substring(1, 1).ToString());
                }
            }

            lstItemsGC.All(x => x.Selected = false);

            foreach (var vSelected in lstSelected)
            {
                foreach (var vItem in lstItemsGC)
                {
                    if (vSelected == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                chkJYXMGC.Items[i].Selected = false;
                foreach (var v in lstSelected)
                {
                    if (chkJYXMGC.Items[i].Value == v)
                    {
                        chkJYXMGC.Items[i].Selected = true;
                    }
                }
            }
        }

        protected void btnFilter_Click(object sender, EventArgs e)
        {
            List<string> lstSelected = new List<string>();
            string strJYLB = drpTestTypeGC.SelectedValue;
            string strCLZL = drpCLZLGC.SelectedValue;
            string strSYXZ = drpSYXZGC.SelectedValue;


            bool IsOut10Year = false;
            if (!string.IsNullOrEmpty(txtCCDJRQGC.Text) && gfValidate.Is_DateTime(txtCCDJRQGC.Text))
            {
                IsOut10Year = Convert.ToDateTime(txtCCDJRQGC.Text).AddYears(10) > DateTime.Now ? true : false;
            }

            string strLW = drpLWCXGC.SelectedValue;

            int iZZS = Convert.ToInt32(drpZZSGC.SelectedValue);

            if (strJYLB == "01" || strJYLB == "05" || strJYLB == "02")
            {
                if (strJYLB == "01" || strJYLB == "05")
                {
                    lstSelected.Add("M1");// 外廓尺寸
                }

                lstSelected.Add("F1");// 外观
                lstSelected.Add("C1");// 底盘部件
                lstSelected.Add("B0");// 驻车制动
                for (int i = 1; i <= iZZS; i++)
                {
                    // 行车制动 
                    lstSelected.Add("B" + i);
                    lstSelected.Add("Z" + i);
                }
            }

            lstItemsGC.All(x => x.Selected = false);

            foreach (var vSelected in lstSelected)
            {
                foreach (var vItem in lstItemsGC)
                {
                    if (vSelected == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }


            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                chkJYXMGC.Items[i].Selected = false;
                foreach (var v in lstSelected)
                {
                    if (chkJYXMGC.Items[i].Value == v)
                    {
                        chkJYXMGC.Items[i].Selected = true;
                    }
                }
            }
        }

        protected void btnSaveGC_Click(object sender, EventArgs e)
        {
            string strTestTypeGC = drpTestTypeGC.SelectedValue + ",";
            string strAJLSHGC = txtAJLSHGC.Text.Trim();
            string strHPHMGC_C = txtHPHMGC.Text.Trim().ToUpper();
            string strHPHMGC_H = txtHPHMStartGC.Text.Trim().ToUpper();
            string strHPHMGC = strHPHMGC_H + strHPHMGC_C;

            if (!strHPHMGC.Contains("挂"))
            {
                strHPHMGC += "挂";
            }
            string strHPZLGC = drpHPZLGC.SelectedValue;
            string strVINGC = txtVINGC.Text.Trim().ToUpper();

            string strCLZLGC = drpCLZLGC.SelectedValue;
            string strSYRGC = txtSYRGC.Text.Trim();
            string strAddressGC = txtAddressGC.Text.Trim();
            string strTelGC = txtTelGC.Text.Trim();
            string strSYXZGC = drpSYXZGC.SelectedValue;
            string strPPGC = txtPPGC.Text.Trim();
            string strXHGC = txtXHGC.Text.Trim().ToUpper();
            string strCCRQGC = txtCCRQGC.Text.Trim();
            string strCCDJRQGC = txtCCDJRQGC.Text.Trim();
            string strZZLGC = txtZZLGC.Text.Trim();
            string strZBZLGC = txtZBZLGC.Text.Trim();
            string strHDZZLGC = txtHDZZLGC.Text.Trim();
            string strZZSGC = drpZZSGC.SelectedValue;
            string strZCZWZGC = "";
            string strCSCGC = txtCSCGC.Text.Trim();
            string strCSKGC = txtCSKGC.Text.Trim();
            string strCSGGC = txtCSGGC.Text.Trim();
            string strTestStatus = rbtnTestGC.SelectedValue;
            string strLWCXGC = drpLWCXGC.SelectedValue;

            if (string.IsNullOrEmpty(strHPHMGC_H))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车号牌号码开头不能为空！");
                txtHPHMStartGC.Focus();
                txtHPHMStartGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtHPHMStartGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strHPHMGC_C))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车号牌号码不能为空！");
                txtHPHMGC.Focus();
                txtHPHMGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtHPHMGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strVINGC) == false)
            {
                txtVINGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strSYRGC) == false)
            {
                txtSYRGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strAddressGC) == false)
            {
                txtAddressGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strTelGC) == false)
            {
                txtTelGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strPPGC) == false)
            {
                txtPPGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strXHGC) == false)
            {
                txtXHGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCCRQGC) == false)
            {
                if (gfValidate.Is_DateTime(strCCRQGC) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车出厂年月不是有效的日期格式！");
                    txtCCRQGC.Focus();
                    txtCCRQGC.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtCCRQGC.BackColor = Color.White;
                }
            }

            if (string.IsNullOrEmpty(strCCDJRQGC) == false)
            {
                if (gfValidate.Is_DateTime(strCCRQGC) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车初始登记日期不是有效的日期格式！");
                    txtCCDJRQGC.Focus();
                    txtCCDJRQGC.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtCCDJRQGC.BackColor = Color.White;
                }
            }

            bool bTogether = chkTogether.Checked;
            string strGLHPHM = "";
            if (bTogether)
            {
                strGLHPHM = txtGLHPHM.Text.Trim();
                if (string.IsNullOrEmpty(strGLHPHM) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "关联号牌号码不能为空！");
                    txtGLHPHM.Focus();
                    txtGLHPHM.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtGLHPHM.BackColor = Color.White;
                }
            }

            if (string.IsNullOrEmpty(strZZLGC) == false)
            {
                txtZZLGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strZBZLGC) == false)
            {
                txtZBZLGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCSCGC) == false)
            {
                txtCSCGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCSKGC) == false)
            {
                txtCSKGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCSGGC) == false)
            {
                txtCSGGC.BackColor = Color.White;
            }

            string strJYXMGC = "";

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                if (chkJYXMGC.Items[i].Selected)
                {
                    strJYXMGC += chkJYXMGC.Items[i].Value + ",";
                }
            }

            for (int i = 0; i < chkZCZWZGC.Items.Count; i++)
            {
                if (chkZCZWZGC.Items[i].Selected)
                {
                    strZCZWZGC += chkZCZWZGC.Items[i].Value + ",";
                }
            }

            string strFirstTestGC = rbtnTestGC.SelectedValue;

            LOGIN_VEHICLE_INFO info_GC = new LOGIN_VEHICLE_INFO();
            string strVEHICLEIDGC = strHPZLGC + strHPHMGC;
            info_GC.VEHICLEID = strVEHICLEIDGC;
            info_GC.HPHM = strHPHMGC;
            info_GC.CLZL = drpCLZLGC.SelectedItem.Text;
            info_GC.CLZLDH = drpCLZLGC.SelectedItem.Value;
            info_GC.HPZL = drpHPZLGC.SelectedItem.Text;
            info_GC.HPZLDH = strHPZLGC;
            info_GC.VIN = strVINGC;
            info_GC.JYLB = drpTestTypeGC.SelectedItem.Text;
            info_GC.JYLBDH = strTestTypeGC;
            info_GC.PP = strPPGC;
            info_GC.XH = strXHGC;
            info_GC.PPXH = strPPGC + strXHGC;
            info_GC.ZCZWZ = strZCZWZGC;
            info_GC.CCDJRQ = strCCDJRQGC;
            info_GC.CCRQ = strCCRQGC;
            info_GC.ZBZL = strZBZLGC;
            info_GC.ZZL = strZZLGC;
            info_GC.SYR = strSYRGC;
            info_GC.LXDZ = strAddressGC;
            info_GC.LXDH = strTelGC;
            info_GC.SYXZ = drpSYXZGC.SelectedItem.Text;
            info_GC.SYXZDH = drpSYXZGC.SelectedItem.Value;
            info_GC.HDZH = strHDZZLGC;
            info_GC.JYXM = strJYXMGC;
            info_GC.CSC = strCSCGC;
            info_GC.CSK = strCSKGC;
            info_GC.CSG = strCSGGC;
            info_GC.DLY = userInfo.UserName;
            info_GC.ZZS = drpZZSGC.SelectedValue;
            info_GC.LWCXWZJLDH = drpLWCXGC.SelectedItem.Value;
            info_GC.LWCXWZJL = drpLWCXGC.SelectedItem.Text;
            if(bTogether)
            {
                info_GC.GLCHPHM = txtGLHPHM.Text.Trim();
            }

            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            var vRet_Login_GC = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLGC);

            DbFactory factory = new DbFactory();

            if (vRet_Login_GC != null)
            {
                factory.Add(bll.UpdateSQL(info_GC, vRet_Login_GC.ID));
            }
            else
            {
                factory.Add(bll.InsertSQL(info_GC));
            }

            if (string.IsNullOrEmpty(userInfo.UserName))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前没有授权,请退出系统重新登录！");
                return;
            }

            bool bOnGoing = LoginHelper.GetVehicleStatus(strVEHICLEIDGC);
            if (bOnGoing)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车辆【" + strVEHICLEIDGC + "】正在检测，不能保存当前信息！");
                return;
            }

            bool bRet = factory.Execute();
            if (bRet)
            {
                hidGCID.Value = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLGC).ID.ToString();
                LoginHelper.SavePPXHAndFDJXH(info_GC);
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车牌号码【" + strHPHMGC + "】保存成功！");
                btnSendGC.Enabled = true;
                btnSendGC.CssClass = "btnSendEnabled";
            }
            else
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车牌号码【" + strHPHMGC + "】保存失败！");
                return;
            }

            if (string.IsNullOrEmpty(userInfo.UserName))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前没有授权,请退出系统重新登录！");
                return;
            }
        }

        protected void btnSearchGC_Click(object sender, EventArgs e)
        {
            string strHPHMGCStart = txtHPHMStartGC.Text.Trim().ToUpper();
            string strHPHM = strHPHMGCStart + txtHPHMGC.Text.Trim().ToUpper();
            string strVIN = txtVINGC.Text.Trim();
            string strHPZL = drpHPZLGC.SelectedValue;

            if (string.IsNullOrEmpty(strHPHM) && string.IsNullOrEmpty(strVIN))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请输入号牌号码或者VIN进行查询！");
                return;
            }

            if (!strHPHM.Contains("挂"))
            {
                strHPHM = strHPHM + "挂";
            }

            if (chkSFLWGC.Checked)
            {
                string strJYJGBH = "xxxx";

                string xtlb = "";//系统类别
                //接口提供者的业务类别代码，默认为“18”（代表机动车检验监管系统）
                string jkxlh = "";//接口序列号
                //由外挂系统请求服务平台授权生成下发
                string jkid = "";//接口标志
                //5位，由系统类别＋C＋两位接口顺序号组成，用于唯一表示一个接口。

                var doc = new XDocument(
                    new XElement("root",
                        new XElement("QueryCondition",
                            new XElement("hphm", strHPHM),
                            new XElement("hpzl", strHPZL),
                            new XElement("clsbdh", strVIN),
                            new XElement("jyjgbh", strJYJGBH)
                            )
                        )
                    );
                string QueryXmlDoc = doc.ToString();
                //localhost.myWebService call = new localhost.myWebService();
                string result = "";// call.queryObjectOut(xtlb, jkxlh, jkid, QueryXmlDoc);

                StringReader reader = new StringReader(result);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode root = xmlDoc.SelectSingleNode("//vehispara");
                if (root != null)
                {
                    LOGIN_VEHICLE_INFO info = new LOGIN_VEHICLE_INFO();

                    info.JYLBDH = root.SelectSingleNode("jylb").InnerText;
                    info.ZYWLBDH = root.SelectSingleNode("ywlx").InnerText;
                    info.HPHM = root.SelectSingleNode("hphm").InnerText;
                    info.HPZLDH = root.SelectSingleNode("hpzl").InnerText;
                    info.VIN = root.SelectSingleNode("clsbdh").InnerText;

                    info.SYR = root.SelectSingleNode("syr").InnerText;
                    info.LXDZ = root.SelectSingleNode("zsxzqh").InnerText;
                    info.SYXZDH = root.SelectSingleNode("syxz").InnerText;
                    info.PP = root.SelectSingleNode("clpp1").InnerText;
                    info.XH = root.SelectSingleNode("clxh").InnerText;
                    info.FDJH = root.SelectSingleNode("fdjh").InnerText;
                    info.CCDJRQ = root.SelectSingleNode("ccdjrq").InnerText;
                    info.CYS = root.SelectSingleNode("hdzk").InnerText;
                    info.ZZL = root.SelectSingleNode("zzl").InnerText;
                    info.ZBZL = root.SelectSingleNode("zbzl").InnerText;
                    info.HDZH = root.SelectSingleNode("hdzzl").InnerText;
                    info.CSC = root.SelectSingleNode("cwkc").InnerText;
                    info.CSG = root.SelectSingleNode("cwkg").InnerText;
                    info.CSK = root.SelectSingleNode("cwkk").InnerText;
                    info.ZXZLXDH = root.SelectSingleNode("zxxs").InnerText;
                    info.ZXZXJXSDH = root.SelectSingleNode("zxzxjxs").InnerText;
                    info.QZDZDH = root.SelectSingleNode("qzdz").InnerText;
                    info.YGGSNFKTDH = root.SelectSingleNode("ygddtz").InnerText;
                    info.ZCZWZ = root.SelectSingleNode("zczw").InnerText;
                    info.QDXSDH = root.SelectSingleNode("qdxs").InnerText;
                    info.JZZZWZ = root.SelectSingleNode("jzzzwz").InnerText;
                    info.RLLBDH = root.SelectSingleNode("rlzl").InnerText;
                    info.ZGSJCS = root.SelectSingleNode("zgsjcs").InnerText;
                    info.LWCXWZJLDH = root.SelectSingleNode("lwcxwzjldh").InnerText;
                    info.ZZS = root.SelectSingleNode("zzs").InnerText;

                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果为空！");
                }
            }
            else
            {
                LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
                string strJYLB = drpTestTypeGC.SelectedValue + ",";
                string strSql = "";
                if (!string.IsNullOrEmpty(strHPHM))
                {
                    strSql = "VEHICLEID='" + drpHPZLGC.SelectedValue + strHPHM + "'  and HPZLDH='" + strHPZL + "' order by ID desc";
                }
                else if (!string.IsNullOrEmpty(strVIN))
                {
                    strSql = "VIN='" + strVIN + "'  and HPZLDH='" + strHPZL + "' order by ID desc";
                }

                LOGIN_VEHICLE_INFO[] infos = bll.GetModelList(strSql);

                if (infos.Length == 1)
                {
                    BindQCLC(infos[0].HPHM, infos[0].HPZLDH);
                    hidGCID.Value = infos[0].ID.ToString();
                }
                else if (infos.Length > 1)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果大于1条，显示为最近记录！");
                    BindQCLC(infos[0].HPHM, infos[0].HPZLDH);
                    hidGCID.Value = infos[0].ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果为空！");
                    ResetAllGC();
                }
            }
        }

        private void BindQCLC(string strHPHMGC, string strHPZLDHGC)
        {
            var vInfo = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLDHGC);

            //总轴数
            if (string.IsNullOrEmpty(vInfo.ZZS) == false)
            {
                drpZZSGC.SelectedValue = vInfo.ZZS;
                drpZZSGC_SelectedIndexChanged(null, null);
            }

            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpTestTypeGC.ID,"JYLBDH"));
            lstControls.Add(drpTestTypeGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAJLSHGC.ID, "AJLSH"));
            lstControls.Add(txtAJLSHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMGC.ID, "HPHM"));
            lstControls.Add(txtHPHMGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMStartGC.ID, "HPHM"));
            lstControls.Add(txtHPHMStartGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZLGC.ID, "HPZLDH"));
            lstControls.Add(drpHPZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID, "ZCZWZ"));
            lstControls.Add(chkZCZWZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtVINGC.ID, "VIN"));
            lstControls.Add(txtVINGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID, "CLZLDH"));
            lstControls.Add(drpCLZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYRGC.ID, "SYR"));
            lstControls.Add(txtSYRGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddressGC.ID, "LXDZ"));
            lstControls.Add(txtAddressGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtTelGC.ID, "LXDH"));
            lstControls.Add(txtTelGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZGC.ID, "SYXZDH"));
            lstControls.Add(drpSYXZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtPPGC.ID, "PP"));
            lstControls.Add(txtPPGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtXHGC.ID, "XH"));
            lstControls.Add(txtXHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQGC.ID, "CCRQ"));
            lstControls.Add(txtCCRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCDJRQGC.ID, "CCDJRQ"));
            lstControls.Add(txtCCDJRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID, "ZZL"));
            lstControls.Add(txtZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID, "ZBZL"));
            lstControls.Add(txtZBZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID, "HDZH"));
            lstControls.Add(txtHDZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID, "CSC"));
            lstControls.Add(txtCSCGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID, "CSK"));
            lstControls.Add(txtCSKGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID, "CSG"));
            lstControls.Add(txtCSGGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpLWCXGC.ID, "LWCXWZJLDH"));
            lstControls.Add(drpLWCXGC);

            if (!string.IsNullOrEmpty(vInfo.GLCHPHM.Trim()))
            {
                chkTogether.Checked = true;
                txtGLHPHM.Text = vInfo.GLCHPHM;
            }
            else
            {
                chkTogether.Checked = false;
                txtGLHPHM.Text = "";
            }

            LoginHelper.LoadData(vInfo, lstCtl, lstControls);

            string strJYXM = "";
            LoginHelper.ConfirmJCXS(vInfo, "A", rbtnTestGC, lblJCCSGC, out strJYXM);

            if (rbtnTestGC.SelectedValue == "0")
            {
                strJYXM = vInfo.JYXM;
            }

            LoginHelper.BindJYXM(strJYXM, chkJYXMGC, lstItemsGC);
            LoginHelper.ResetAllValidate(GetType(), this);
        }

        protected void chkZCZWZGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool b = false;
            for (int i = 0; i < chkZCZWZGC.Items.Count; i++)
            {
                if (chkZCZWZGC.Items[i].Selected)
                {
                    b = true;
                }
            }

            if (b == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "必须选择一个驻车轴！");
                chkZCZWZGC.Items[1].Selected = true;
                return;
            }
        }

        protected void btnResetGC_Click(object sender, EventArgs e)
        {
            ResetAllGC();
        }

        protected void btnSearchGCPPXH_Click(object sender, EventArgs e)
        {
            string strPPGC = txtPPGC.Text.Trim();
            string strXHGC = txtXHGC.Text.Trim();
            TYPE_CX_CONTENT_BLL bll = new TYPE_CX_CONTENT_BLL();
            TYPE_CX_CONTENT[] m_TYPE_CX_CONTENT = bll.GetModelList("PP='" + strPPGC + "' and XH='" + strXHGC + "' order by ID desc");

            if (m_TYPE_CX_CONTENT.Length > 0)
            {
                TYPE_CX_CONTENT vContent = m_TYPE_CX_CONTENT[0];

                if (!string.IsNullOrEmpty(vContent.ZZS))
                {
                    drpZZSGC.SelectedValue = vContent.ZZS;
                    drpZZSGC_SelectedIndexChanged(null, null);
                }

                List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
                List<Control> lstControls = new List<Control>();

                lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID.ToString(), "ZCZWZ"));
                lstControls.Add(chkZCZWZGC);

                lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID.ToString(), "CLZL"));
                lstControls.Add(drpCLZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID.ToString(), "ZZL"));
                lstControls.Add(txtZZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID.ToString(), "ZBZL"));
                lstControls.Add(txtZBZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID.ToString(), "HDZH"));
                lstControls.Add(txtHDZZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID.ToString(), "CSC"));
                lstControls.Add(txtCSCGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID.ToString(), "CSK"));
                lstControls.Add(txtCSKGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID.ToString(), "CSG"));
                lstControls.Add(txtCSGGC);

                LoginHelper.GetPPXH(vContent, lstCtl, lstControls);
            }
        }

        protected void chkTogether_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTogether.Checked)
            {
                txtGLHPHM.ReadOnly = false;
                txtGLHPHM.CssClass = "csstextbox";
            }
            else
            {
                txtGLHPHM.ReadOnly = true;
                txtGLHPHM.CssClass = "csstextboxreadonly";
            }
        }

        protected void lbtnLoginedShow_Click(object sender, EventArgs e)
        {
            if (divLoginList.Visible == false)
            {
                lbtnLoginedShow.Text = "收 起︽";
                divLoginList.Visible = true;
            }
            else
            {
                lbtnLoginedShow.Text = "展 开︾";
                divLoginList.Visible = false;
            }
        }
    }
}